{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ff8ac8ad-c571-48a3-9c86-7398455d9abe",
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "\n",
    "import pandas as pd\n",
    "import h5py\n",
    "import numpy as np\n",
    "from pathlib import Path\n",
    "import zipline\n",
    "\n",
    "%load_ext zipline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b6f5162d-5e0f-4d86-91a4-c8ccd1e0fca1",
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_STORE = Path('assets.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ad9fa1bc-dfd0-4395-bb6f-4abbfaec60e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "with pd.HDFStore(DATA_STORE) as store:\n",
    "    store.put('code', code_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0bfdd585-275c-43f3-a1e4-db69bfbb0b9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "code_df = pd.read_csv('../datagen/clist.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "33054411-1f1d-4801-8be9-4586565a60bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "with pd.HDFStore(DATA_STORE) as store:\n",
    "    cdf = store.get('code')\n",
    "# cdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3c62c402-148e-4139-ae43-71a6bf0c85df",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "parser_f() got an unexpected keyword argument 'index_label'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0mTraceback (most recent call last)",
      "\u001b[0;32m<ipython-input-26-244a0b761f12>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'../datagen/dataindex/000001.XSHG_上证指数.csv'\u001b[0m\u001b[0;34m,\u001b[0m  \u001b[0mindex_label\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'date'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: parser_f() got an unexpected keyword argument 'index_label'"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('../datagen/dataindex/000001.XSHG_上证指数.csv',  index_label = 'date')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f6626b0a-da60-4d42-84b7-ce1bea421357",
   "metadata": {},
   "outputs": [],
   "source": [
    "with pd.HDFStore(DATA_STORE) as store:\n",
    "    store.put('sz', df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d2879c63-6e29-447c-b7d6-008dd7a775e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def set_hdata(name, df):\n",
    "    with pd.HDFStore(DATA_STORE) as store:\n",
    "        store.put(name, df)\n",
    "def get_hdata(name, df):\n",
    "    with pd.HDFStore(DATA_STORE) as store:\n",
    "        return store.get(name)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "b9d9c1ec-c69a-4911-92c3-e2ad6c58fd07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>high</th>\n",
       "      <th>volume</th>\n",
       "      <th>money</th>\n",
       "      <th>name</th>\n",
       "      <th>code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>1260.7800</td>\n",
       "      <td>1242.7700</td>\n",
       "      <td>1238.1800</td>\n",
       "      <td>1260.7800</td>\n",
       "      <td>8.161770e+08</td>\n",
       "      <td>4.418452e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2005-01-05</td>\n",
       "      <td>1241.6800</td>\n",
       "      <td>1251.9400</td>\n",
       "      <td>1235.7500</td>\n",
       "      <td>1258.5800</td>\n",
       "      <td>8.678651e+08</td>\n",
       "      <td>4.916589e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2005-01-06</td>\n",
       "      <td>1252.4900</td>\n",
       "      <td>1239.4300</td>\n",
       "      <td>1234.2400</td>\n",
       "      <td>1252.7300</td>\n",
       "      <td>7.922254e+08</td>\n",
       "      <td>4.381370e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2005-01-07</td>\n",
       "      <td>1239.3200</td>\n",
       "      <td>1244.7500</td>\n",
       "      <td>1235.5100</td>\n",
       "      <td>1256.3100</td>\n",
       "      <td>8.940871e+08</td>\n",
       "      <td>5.040042e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2005-01-10</td>\n",
       "      <td>1243.5800</td>\n",
       "      <td>1252.4000</td>\n",
       "      <td>1236.0900</td>\n",
       "      <td>1252.7200</td>\n",
       "      <td>7.234683e+08</td>\n",
       "      <td>4.118292e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2005-01-11</td>\n",
       "      <td>1252.7100</td>\n",
       "      <td>1257.4600</td>\n",
       "      <td>1247.8400</td>\n",
       "      <td>1260.8700</td>\n",
       "      <td>7.725570e+08</td>\n",
       "      <td>4.368276e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2005-01-12</td>\n",
       "      <td>1257.1700</td>\n",
       "      <td>1256.9200</td>\n",
       "      <td>1246.4200</td>\n",
       "      <td>1257.1900</td>\n",
       "      <td>6.769585e+08</td>\n",
       "      <td>3.799863e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2005-01-13</td>\n",
       "      <td>1255.7200</td>\n",
       "      <td>1256.3100</td>\n",
       "      <td>1251.0200</td>\n",
       "      <td>1259.5000</td>\n",
       "      <td>8.746707e+08</td>\n",
       "      <td>5.003681e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2005-01-14</td>\n",
       "      <td>1255.8700</td>\n",
       "      <td>1245.6200</td>\n",
       "      <td>1243.8700</td>\n",
       "      <td>1268.8600</td>\n",
       "      <td>9.898327e+08</td>\n",
       "      <td>5.272488e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2005-01-17</td>\n",
       "      <td>1235.5700</td>\n",
       "      <td>1216.6500</td>\n",
       "      <td>1214.0700</td>\n",
       "      <td>1236.4000</td>\n",
       "      <td>1.002856e+09</td>\n",
       "      <td>5.434886e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2005-01-18</td>\n",
       "      <td>1215.7800</td>\n",
       "      <td>1225.4500</td>\n",
       "      <td>1207.0500</td>\n",
       "      <td>1226.0400</td>\n",
       "      <td>1.019029e+09</td>\n",
       "      <td>5.294355e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2005-01-19</td>\n",
       "      <td>1225.0800</td>\n",
       "      <td>1218.1100</td>\n",
       "      <td>1214.6300</td>\n",
       "      <td>1225.0800</td>\n",
       "      <td>9.377195e+08</td>\n",
       "      <td>4.677974e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2005-01-20</td>\n",
       "      <td>1213.3700</td>\n",
       "      <td>1204.3900</td>\n",
       "      <td>1199.1700</td>\n",
       "      <td>1213.9600</td>\n",
       "      <td>1.031028e+09</td>\n",
       "      <td>5.383794e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2005-01-21</td>\n",
       "      <td>1201.9300</td>\n",
       "      <td>1234.4800</td>\n",
       "      <td>1189.2100</td>\n",
       "      <td>1237.9100</td>\n",
       "      <td>1.697008e+09</td>\n",
       "      <td>9.001891e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2005-01-24</td>\n",
       "      <td>1258.0200</td>\n",
       "      <td>1255.7800</td>\n",
       "      <td>1239.8000</td>\n",
       "      <td>1265.9500</td>\n",
       "      <td>1.802021e+09</td>\n",
       "      <td>9.786783e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2005-01-25</td>\n",
       "      <td>1252.3500</td>\n",
       "      <td>1254.2300</td>\n",
       "      <td>1239.1600</td>\n",
       "      <td>1254.8700</td>\n",
       "      <td>1.181392e+09</td>\n",
       "      <td>6.439330e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2005-01-26</td>\n",
       "      <td>1252.3700</td>\n",
       "      <td>1241.9600</td>\n",
       "      <td>1240.1300</td>\n",
       "      <td>1254.2300</td>\n",
       "      <td>9.640691e+08</td>\n",
       "      <td>5.351521e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2005-01-27</td>\n",
       "      <td>1239.5800</td>\n",
       "      <td>1225.8900</td>\n",
       "      <td>1223.8800</td>\n",
       "      <td>1241.1400</td>\n",
       "      <td>9.412829e+08</td>\n",
       "      <td>4.955028e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2005-01-28</td>\n",
       "      <td>1223.7300</td>\n",
       "      <td>1213.6700</td>\n",
       "      <td>1208.8600</td>\n",
       "      <td>1226.3000</td>\n",
       "      <td>8.170557e+08</td>\n",
       "      <td>4.199937e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2005-01-31</td>\n",
       "      <td>1210.7600</td>\n",
       "      <td>1191.8200</td>\n",
       "      <td>1190.1700</td>\n",
       "      <td>1210.7600</td>\n",
       "      <td>9.078062e+08</td>\n",
       "      <td>4.668010e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2005-02-01</td>\n",
       "      <td>1189.5000</td>\n",
       "      <td>1188.9300</td>\n",
       "      <td>1187.2600</td>\n",
       "      <td>1203.0700</td>\n",
       "      <td>9.340222e+08</td>\n",
       "      <td>4.907931e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2005-02-02</td>\n",
       "      <td>1189.5000</td>\n",
       "      <td>1252.5000</td>\n",
       "      <td>1189.5000</td>\n",
       "      <td>1253.1600</td>\n",
       "      <td>1.905406e+09</td>\n",
       "      <td>1.039727e+10</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2005-02-03</td>\n",
       "      <td>1253.8100</td>\n",
       "      <td>1242.3100</td>\n",
       "      <td>1236.1800</td>\n",
       "      <td>1269.1500</td>\n",
       "      <td>2.041522e+09</td>\n",
       "      <td>1.089729e+10</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2005-02-04</td>\n",
       "      <td>1238.6100</td>\n",
       "      <td>1269.0000</td>\n",
       "      <td>1235.6400</td>\n",
       "      <td>1274.1200</td>\n",
       "      <td>1.702829e+09</td>\n",
       "      <td>9.664345e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2005-02-16</td>\n",
       "      <td>1276.0200</td>\n",
       "      <td>1278.8800</td>\n",
       "      <td>1270.3200</td>\n",
       "      <td>1291.4600</td>\n",
       "      <td>1.444546e+09</td>\n",
       "      <td>7.980114e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2005-02-17</td>\n",
       "      <td>1280.0300</td>\n",
       "      <td>1276.1300</td>\n",
       "      <td>1263.7100</td>\n",
       "      <td>1280.0300</td>\n",
       "      <td>1.121861e+09</td>\n",
       "      <td>6.103111e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2005-02-18</td>\n",
       "      <td>1275.6600</td>\n",
       "      <td>1258.9700</td>\n",
       "      <td>1258.5600</td>\n",
       "      <td>1278.6200</td>\n",
       "      <td>1.068805e+09</td>\n",
       "      <td>5.785502e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2005-02-21</td>\n",
       "      <td>1259.5300</td>\n",
       "      <td>1284.4800</td>\n",
       "      <td>1259.5100</td>\n",
       "      <td>1284.9400</td>\n",
       "      <td>1.253692e+09</td>\n",
       "      <td>6.930692e+09</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2005-02-22</td>\n",
       "      <td>1285.6300</td>\n",
       "      <td>1309.2800</td>\n",
       "      <td>1282.7800</td>\n",
       "      <td>1312.5300</td>\n",
       "      <td>2.260282e+09</td>\n",
       "      <td>1.277351e+10</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2005-02-23</td>\n",
       "      <td>1309.6200</td>\n",
       "      <td>1309.4700</td>\n",
       "      <td>1299.1500</td>\n",
       "      <td>1316.5900</td>\n",
       "      <td>2.418913e+09</td>\n",
       "      <td>1.369923e+10</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4045</th>\n",
       "      <td>2021-08-24</td>\n",
       "      <td>3482.2700</td>\n",
       "      <td>3514.4700</td>\n",
       "      <td>3481.1400</td>\n",
       "      <td>3522.7000</td>\n",
       "      <td>4.302365e+10</td>\n",
       "      <td>6.160841e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4046</th>\n",
       "      <td>2021-08-25</td>\n",
       "      <td>3517.9200</td>\n",
       "      <td>3540.3800</td>\n",
       "      <td>3510.0700</td>\n",
       "      <td>3540.3900</td>\n",
       "      <td>4.500470e+10</td>\n",
       "      <td>5.986119e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4047</th>\n",
       "      <td>2021-08-26</td>\n",
       "      <td>3537.3100</td>\n",
       "      <td>3501.6600</td>\n",
       "      <td>3499.4500</td>\n",
       "      <td>3537.3200</td>\n",
       "      <td>5.029031e+10</td>\n",
       "      <td>6.223935e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4048</th>\n",
       "      <td>2021-08-27</td>\n",
       "      <td>3494.4200</td>\n",
       "      <td>3522.1600</td>\n",
       "      <td>3493.3800</td>\n",
       "      <td>3530.1900</td>\n",
       "      <td>4.553459e+10</td>\n",
       "      <td>5.955187e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4049</th>\n",
       "      <td>2021-08-30</td>\n",
       "      <td>3535.0700</td>\n",
       "      <td>3528.1500</td>\n",
       "      <td>3512.9900</td>\n",
       "      <td>3539.4900</td>\n",
       "      <td>5.127857e+10</td>\n",
       "      <td>6.991162e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4050</th>\n",
       "      <td>2021-08-31</td>\n",
       "      <td>3519.0200</td>\n",
       "      <td>3543.9400</td>\n",
       "      <td>3496.3900</td>\n",
       "      <td>3543.9400</td>\n",
       "      <td>5.242051e+10</td>\n",
       "      <td>7.035048e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4051</th>\n",
       "      <td>2021-09-01</td>\n",
       "      <td>3543.8700</td>\n",
       "      <td>3567.1000</td>\n",
       "      <td>3514.6700</td>\n",
       "      <td>3582.3200</td>\n",
       "      <td>6.672763e+10</td>\n",
       "      <td>8.425290e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4052</th>\n",
       "      <td>2021-09-02</td>\n",
       "      <td>3559.9000</td>\n",
       "      <td>3597.0400</td>\n",
       "      <td>3557.6800</td>\n",
       "      <td>3597.3700</td>\n",
       "      <td>5.726840e+10</td>\n",
       "      <td>6.911133e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4053</th>\n",
       "      <td>2021-09-03</td>\n",
       "      <td>3602.7400</td>\n",
       "      <td>3581.7300</td>\n",
       "      <td>3569.4000</td>\n",
       "      <td>3613.9500</td>\n",
       "      <td>6.145324e+10</td>\n",
       "      <td>7.438408e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4054</th>\n",
       "      <td>2021-09-06</td>\n",
       "      <td>3580.1400</td>\n",
       "      <td>3621.8600</td>\n",
       "      <td>3580.1400</td>\n",
       "      <td>3626.2900</td>\n",
       "      <td>5.217133e+10</td>\n",
       "      <td>6.540857e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4055</th>\n",
       "      <td>2021-09-07</td>\n",
       "      <td>3621.7100</td>\n",
       "      <td>3676.5900</td>\n",
       "      <td>3615.1400</td>\n",
       "      <td>3681.9300</td>\n",
       "      <td>5.477219e+10</td>\n",
       "      <td>6.588679e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4056</th>\n",
       "      <td>2021-09-08</td>\n",
       "      <td>3673.4000</td>\n",
       "      <td>3675.1900</td>\n",
       "      <td>3661.0000</td>\n",
       "      <td>3695.3200</td>\n",
       "      <td>5.864362e+10</td>\n",
       "      <td>6.743485e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4057</th>\n",
       "      <td>2021-09-09</td>\n",
       "      <td>3666.8200</td>\n",
       "      <td>3693.1300</td>\n",
       "      <td>3662.1600</td>\n",
       "      <td>3693.4500</td>\n",
       "      <td>6.048103e+10</td>\n",
       "      <td>6.794654e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4058</th>\n",
       "      <td>2021-09-10</td>\n",
       "      <td>3691.1900</td>\n",
       "      <td>3703.1100</td>\n",
       "      <td>3681.6400</td>\n",
       "      <td>3722.8700</td>\n",
       "      <td>6.352004e+10</td>\n",
       "      <td>7.590846e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4059</th>\n",
       "      <td>2021-09-13</td>\n",
       "      <td>3699.2500</td>\n",
       "      <td>3715.3700</td>\n",
       "      <td>3692.8200</td>\n",
       "      <td>3716.8300</td>\n",
       "      <td>5.574840e+10</td>\n",
       "      <td>6.961924e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4060</th>\n",
       "      <td>2021-09-14</td>\n",
       "      <td>3709.6300</td>\n",
       "      <td>3662.6000</td>\n",
       "      <td>3655.6300</td>\n",
       "      <td>3723.8500</td>\n",
       "      <td>5.649524e+10</td>\n",
       "      <td>6.937781e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4061</th>\n",
       "      <td>2021-09-15</td>\n",
       "      <td>3651.1600</td>\n",
       "      <td>3656.2200</td>\n",
       "      <td>3638.3200</td>\n",
       "      <td>3677.5300</td>\n",
       "      <td>4.749700e+10</td>\n",
       "      <td>6.042315e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4062</th>\n",
       "      <td>2021-09-16</td>\n",
       "      <td>3664.8400</td>\n",
       "      <td>3607.0900</td>\n",
       "      <td>3606.7300</td>\n",
       "      <td>3677.9200</td>\n",
       "      <td>5.467415e+10</td>\n",
       "      <td>6.739553e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4063</th>\n",
       "      <td>2021-09-17</td>\n",
       "      <td>3595.2700</td>\n",
       "      <td>3613.9700</td>\n",
       "      <td>3569.2700</td>\n",
       "      <td>3620.9600</td>\n",
       "      <td>5.168502e+10</td>\n",
       "      <td>6.288344e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4064</th>\n",
       "      <td>2021-09-22</td>\n",
       "      <td>3563.2100</td>\n",
       "      <td>3628.4900</td>\n",
       "      <td>3560.5000</td>\n",
       "      <td>3629.4500</td>\n",
       "      <td>4.722961e+10</td>\n",
       "      <td>5.598747e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4065</th>\n",
       "      <td>2021-09-23</td>\n",
       "      <td>3651.2700</td>\n",
       "      <td>3642.2200</td>\n",
       "      <td>3632.2800</td>\n",
       "      <td>3670.9500</td>\n",
       "      <td>5.349955e+10</td>\n",
       "      <td>6.332189e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4066</th>\n",
       "      <td>2021-09-24</td>\n",
       "      <td>3637.8700</td>\n",
       "      <td>3613.0700</td>\n",
       "      <td>3607.7900</td>\n",
       "      <td>3651.4300</td>\n",
       "      <td>5.073048e+10</td>\n",
       "      <td>6.067886e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4067</th>\n",
       "      <td>2021-09-27</td>\n",
       "      <td>3625.9600</td>\n",
       "      <td>3582.8300</td>\n",
       "      <td>3559.9200</td>\n",
       "      <td>3640.8100</td>\n",
       "      <td>5.108028e+10</td>\n",
       "      <td>6.406736e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4068</th>\n",
       "      <td>2021-09-28</td>\n",
       "      <td>3577.8900</td>\n",
       "      <td>3602.2200</td>\n",
       "      <td>3568.8200</td>\n",
       "      <td>3610.9200</td>\n",
       "      <td>4.441688e+10</td>\n",
       "      <td>5.000820e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4069</th>\n",
       "      <td>2021-09-29</td>\n",
       "      <td>3573.5200</td>\n",
       "      <td>3536.2900</td>\n",
       "      <td>3518.0500</td>\n",
       "      <td>3573.5200</td>\n",
       "      <td>4.525112e+10</td>\n",
       "      <td>5.111069e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4070</th>\n",
       "      <td>2021-09-30</td>\n",
       "      <td>3541.9300</td>\n",
       "      <td>3568.1700</td>\n",
       "      <td>3541.9300</td>\n",
       "      <td>3572.4300</td>\n",
       "      <td>3.956296e+10</td>\n",
       "      <td>4.457347e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4071</th>\n",
       "      <td>2021-10-08</td>\n",
       "      <td>3609.0900</td>\n",
       "      <td>3592.1700</td>\n",
       "      <td>3571.7300</td>\n",
       "      <td>3612.5500</td>\n",
       "      <td>4.071611e+10</td>\n",
       "      <td>4.929648e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4072</th>\n",
       "      <td>2021-10-11</td>\n",
       "      <td>3600.3600</td>\n",
       "      <td>3591.7100</td>\n",
       "      <td>3586.7500</td>\n",
       "      <td>3614.7000</td>\n",
       "      <td>3.943612e+10</td>\n",
       "      <td>4.686738e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4073</th>\n",
       "      <td>2021-10-12</td>\n",
       "      <td>3581.3000</td>\n",
       "      <td>3546.9400</td>\n",
       "      <td>3515.1400</td>\n",
       "      <td>3583.6400</td>\n",
       "      <td>4.053937e+10</td>\n",
       "      <td>4.619835e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4074</th>\n",
       "      <td>2021-10-13</td>\n",
       "      <td>3543.4918</td>\n",
       "      <td>3534.4313</td>\n",
       "      <td>3515.6481</td>\n",
       "      <td>3546.6497</td>\n",
       "      <td>2.035640e+10</td>\n",
       "      <td>2.398793e+11</td>\n",
       "      <td>上证指数</td>\n",
       "      <td>000001.XSHG</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4075 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            date       open      close        low       high        volume  \\\n",
       "0     2005-01-04  1260.7800  1242.7700  1238.1800  1260.7800  8.161770e+08   \n",
       "1     2005-01-05  1241.6800  1251.9400  1235.7500  1258.5800  8.678651e+08   \n",
       "2     2005-01-06  1252.4900  1239.4300  1234.2400  1252.7300  7.922254e+08   \n",
       "3     2005-01-07  1239.3200  1244.7500  1235.5100  1256.3100  8.940871e+08   \n",
       "4     2005-01-10  1243.5800  1252.4000  1236.0900  1252.7200  7.234683e+08   \n",
       "5     2005-01-11  1252.7100  1257.4600  1247.8400  1260.8700  7.725570e+08   \n",
       "6     2005-01-12  1257.1700  1256.9200  1246.4200  1257.1900  6.769585e+08   \n",
       "7     2005-01-13  1255.7200  1256.3100  1251.0200  1259.5000  8.746707e+08   \n",
       "8     2005-01-14  1255.8700  1245.6200  1243.8700  1268.8600  9.898327e+08   \n",
       "9     2005-01-17  1235.5700  1216.6500  1214.0700  1236.4000  1.002856e+09   \n",
       "10    2005-01-18  1215.7800  1225.4500  1207.0500  1226.0400  1.019029e+09   \n",
       "11    2005-01-19  1225.0800  1218.1100  1214.6300  1225.0800  9.377195e+08   \n",
       "12    2005-01-20  1213.3700  1204.3900  1199.1700  1213.9600  1.031028e+09   \n",
       "13    2005-01-21  1201.9300  1234.4800  1189.2100  1237.9100  1.697008e+09   \n",
       "14    2005-01-24  1258.0200  1255.7800  1239.8000  1265.9500  1.802021e+09   \n",
       "15    2005-01-25  1252.3500  1254.2300  1239.1600  1254.8700  1.181392e+09   \n",
       "16    2005-01-26  1252.3700  1241.9600  1240.1300  1254.2300  9.640691e+08   \n",
       "17    2005-01-27  1239.5800  1225.8900  1223.8800  1241.1400  9.412829e+08   \n",
       "18    2005-01-28  1223.7300  1213.6700  1208.8600  1226.3000  8.170557e+08   \n",
       "19    2005-01-31  1210.7600  1191.8200  1190.1700  1210.7600  9.078062e+08   \n",
       "20    2005-02-01  1189.5000  1188.9300  1187.2600  1203.0700  9.340222e+08   \n",
       "21    2005-02-02  1189.5000  1252.5000  1189.5000  1253.1600  1.905406e+09   \n",
       "22    2005-02-03  1253.8100  1242.3100  1236.1800  1269.1500  2.041522e+09   \n",
       "23    2005-02-04  1238.6100  1269.0000  1235.6400  1274.1200  1.702829e+09   \n",
       "24    2005-02-16  1276.0200  1278.8800  1270.3200  1291.4600  1.444546e+09   \n",
       "25    2005-02-17  1280.0300  1276.1300  1263.7100  1280.0300  1.121861e+09   \n",
       "26    2005-02-18  1275.6600  1258.9700  1258.5600  1278.6200  1.068805e+09   \n",
       "27    2005-02-21  1259.5300  1284.4800  1259.5100  1284.9400  1.253692e+09   \n",
       "28    2005-02-22  1285.6300  1309.2800  1282.7800  1312.5300  2.260282e+09   \n",
       "29    2005-02-23  1309.6200  1309.4700  1299.1500  1316.5900  2.418913e+09   \n",
       "...          ...        ...        ...        ...        ...           ...   \n",
       "4045  2021-08-24  3482.2700  3514.4700  3481.1400  3522.7000  4.302365e+10   \n",
       "4046  2021-08-25  3517.9200  3540.3800  3510.0700  3540.3900  4.500470e+10   \n",
       "4047  2021-08-26  3537.3100  3501.6600  3499.4500  3537.3200  5.029031e+10   \n",
       "4048  2021-08-27  3494.4200  3522.1600  3493.3800  3530.1900  4.553459e+10   \n",
       "4049  2021-08-30  3535.0700  3528.1500  3512.9900  3539.4900  5.127857e+10   \n",
       "4050  2021-08-31  3519.0200  3543.9400  3496.3900  3543.9400  5.242051e+10   \n",
       "4051  2021-09-01  3543.8700  3567.1000  3514.6700  3582.3200  6.672763e+10   \n",
       "4052  2021-09-02  3559.9000  3597.0400  3557.6800  3597.3700  5.726840e+10   \n",
       "4053  2021-09-03  3602.7400  3581.7300  3569.4000  3613.9500  6.145324e+10   \n",
       "4054  2021-09-06  3580.1400  3621.8600  3580.1400  3626.2900  5.217133e+10   \n",
       "4055  2021-09-07  3621.7100  3676.5900  3615.1400  3681.9300  5.477219e+10   \n",
       "4056  2021-09-08  3673.4000  3675.1900  3661.0000  3695.3200  5.864362e+10   \n",
       "4057  2021-09-09  3666.8200  3693.1300  3662.1600  3693.4500  6.048103e+10   \n",
       "4058  2021-09-10  3691.1900  3703.1100  3681.6400  3722.8700  6.352004e+10   \n",
       "4059  2021-09-13  3699.2500  3715.3700  3692.8200  3716.8300  5.574840e+10   \n",
       "4060  2021-09-14  3709.6300  3662.6000  3655.6300  3723.8500  5.649524e+10   \n",
       "4061  2021-09-15  3651.1600  3656.2200  3638.3200  3677.5300  4.749700e+10   \n",
       "4062  2021-09-16  3664.8400  3607.0900  3606.7300  3677.9200  5.467415e+10   \n",
       "4063  2021-09-17  3595.2700  3613.9700  3569.2700  3620.9600  5.168502e+10   \n",
       "4064  2021-09-22  3563.2100  3628.4900  3560.5000  3629.4500  4.722961e+10   \n",
       "4065  2021-09-23  3651.2700  3642.2200  3632.2800  3670.9500  5.349955e+10   \n",
       "4066  2021-09-24  3637.8700  3613.0700  3607.7900  3651.4300  5.073048e+10   \n",
       "4067  2021-09-27  3625.9600  3582.8300  3559.9200  3640.8100  5.108028e+10   \n",
       "4068  2021-09-28  3577.8900  3602.2200  3568.8200  3610.9200  4.441688e+10   \n",
       "4069  2021-09-29  3573.5200  3536.2900  3518.0500  3573.5200  4.525112e+10   \n",
       "4070  2021-09-30  3541.9300  3568.1700  3541.9300  3572.4300  3.956296e+10   \n",
       "4071  2021-10-08  3609.0900  3592.1700  3571.7300  3612.5500  4.071611e+10   \n",
       "4072  2021-10-11  3600.3600  3591.7100  3586.7500  3614.7000  3.943612e+10   \n",
       "4073  2021-10-12  3581.3000  3546.9400  3515.1400  3583.6400  4.053937e+10   \n",
       "4074  2021-10-13  3543.4918  3534.4313  3515.6481  3546.6497  2.035640e+10   \n",
       "\n",
       "             money  name         code  \n",
       "0     4.418452e+09  上证指数  000001.XSHG  \n",
       "1     4.916589e+09  上证指数  000001.XSHG  \n",
       "2     4.381370e+09  上证指数  000001.XSHG  \n",
       "3     5.040042e+09  上证指数  000001.XSHG  \n",
       "4     4.118292e+09  上证指数  000001.XSHG  \n",
       "5     4.368276e+09  上证指数  000001.XSHG  \n",
       "6     3.799863e+09  上证指数  000001.XSHG  \n",
       "7     5.003681e+09  上证指数  000001.XSHG  \n",
       "8     5.272488e+09  上证指数  000001.XSHG  \n",
       "9     5.434886e+09  上证指数  000001.XSHG  \n",
       "10    5.294355e+09  上证指数  000001.XSHG  \n",
       "11    4.677974e+09  上证指数  000001.XSHG  \n",
       "12    5.383794e+09  上证指数  000001.XSHG  \n",
       "13    9.001891e+09  上证指数  000001.XSHG  \n",
       "14    9.786783e+09  上证指数  000001.XSHG  \n",
       "15    6.439330e+09  上证指数  000001.XSHG  \n",
       "16    5.351521e+09  上证指数  000001.XSHG  \n",
       "17    4.955028e+09  上证指数  000001.XSHG  \n",
       "18    4.199937e+09  上证指数  000001.XSHG  \n",
       "19    4.668010e+09  上证指数  000001.XSHG  \n",
       "20    4.907931e+09  上证指数  000001.XSHG  \n",
       "21    1.039727e+10  上证指数  000001.XSHG  \n",
       "22    1.089729e+10  上证指数  000001.XSHG  \n",
       "23    9.664345e+09  上证指数  000001.XSHG  \n",
       "24    7.980114e+09  上证指数  000001.XSHG  \n",
       "25    6.103111e+09  上证指数  000001.XSHG  \n",
       "26    5.785502e+09  上证指数  000001.XSHG  \n",
       "27    6.930692e+09  上证指数  000001.XSHG  \n",
       "28    1.277351e+10  上证指数  000001.XSHG  \n",
       "29    1.369923e+10  上证指数  000001.XSHG  \n",
       "...            ...   ...          ...  \n",
       "4045  6.160841e+11  上证指数  000001.XSHG  \n",
       "4046  5.986119e+11  上证指数  000001.XSHG  \n",
       "4047  6.223935e+11  上证指数  000001.XSHG  \n",
       "4048  5.955187e+11  上证指数  000001.XSHG  \n",
       "4049  6.991162e+11  上证指数  000001.XSHG  \n",
       "4050  7.035048e+11  上证指数  000001.XSHG  \n",
       "4051  8.425290e+11  上证指数  000001.XSHG  \n",
       "4052  6.911133e+11  上证指数  000001.XSHG  \n",
       "4053  7.438408e+11  上证指数  000001.XSHG  \n",
       "4054  6.540857e+11  上证指数  000001.XSHG  \n",
       "4055  6.588679e+11  上证指数  000001.XSHG  \n",
       "4056  6.743485e+11  上证指数  000001.XSHG  \n",
       "4057  6.794654e+11  上证指数  000001.XSHG  \n",
       "4058  7.590846e+11  上证指数  000001.XSHG  \n",
       "4059  6.961924e+11  上证指数  000001.XSHG  \n",
       "4060  6.937781e+11  上证指数  000001.XSHG  \n",
       "4061  6.042315e+11  上证指数  000001.XSHG  \n",
       "4062  6.739553e+11  上证指数  000001.XSHG  \n",
       "4063  6.288344e+11  上证指数  000001.XSHG  \n",
       "4064  5.598747e+11  上证指数  000001.XSHG  \n",
       "4065  6.332189e+11  上证指数  000001.XSHG  \n",
       "4066  6.067886e+11  上证指数  000001.XSHG  \n",
       "4067  6.406736e+11  上证指数  000001.XSHG  \n",
       "4068  5.000820e+11  上证指数  000001.XSHG  \n",
       "4069  5.111069e+11  上证指数  000001.XSHG  \n",
       "4070  4.457347e+11  上证指数  000001.XSHG  \n",
       "4071  4.929648e+11  上证指数  000001.XSHG  \n",
       "4072  4.686738e+11  上证指数  000001.XSHG  \n",
       "4073  4.619835e+11  上证指数  000001.XSHG  \n",
       "4074  2.398793e+11  上证指数  000001.XSHG  \n",
       "\n",
       "[4075 rows x 9 columns]"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.rename(columns={df.columns[0]: 'date'}, inplace = True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "312fcc20-f707-4527-b1b6-1834bdcf746d",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = df.groupby('code').agg({'date': [np.min, np.max]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "57ba7a25-f2c7-4e1a-ba7f-8e5158009db2",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.reset_index(inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "1917e251-a958-4609-a482-2575883e23f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "x.reset_index(inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f3ed7839-4fa3-4a64-97c8-00094c401661",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th colspan=\"2\" halign=\"left\">date</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>amin</th>\n",
       "      <th>amax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.XSHG</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>2021-10-13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          code        date            \n",
       "                      amin        amax\n",
       "0  000001.XSHG  2005-01-04  2021-10-13"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "31756f64-5414-4c37-8051-49865e70df2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2005-01-04\n",
       "Name: amin, dtype: object"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.date.amin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "786faa5d-0b9b-4bf6-89d5-42ce53721912",
   "metadata": {},
   "outputs": [],
   "source": [
    "x['start_date'] = x.date.amin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "cb8bbdcf-8a48-4f12-8db7-9739fc3160db",
   "metadata": {},
   "outputs": [],
   "source": [
    "x['end_date'] = x.date.amax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "be44cf0d-9d88-4b02-a78d-2eeee6e9fc59",
   "metadata": {},
   "outputs": [],
   "source": [
    "del x['date']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "2521914b-e163-48ee-a580-af6a9f8b548a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>start_date</th>\n",
       "      <th>end_date</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.XSHG</td>\n",
       "      <td>2005-01-04</td>\n",
       "      <td>2021-10-13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          code  start_date    end_date\n",
       "                                      \n",
       "0  000001.XSHG  2005-01-04  2021-10-13"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "5f6b7ab4-81af-4cbf-9420-eeded850d1e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['code', 'start_date', 'end_date'], dtype='object')"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x.columns.get_level_values(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bda51eb2-9130-4c87-8389-38a48c5149a4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
